var url="https://item.jd.com/5523485.html#crumb-wrap";
var page = require('webpage').create();
page.settings.loadImages = false;

page.onError = function(msg,trace){
	var msgStack = ['ERROR: ' + msg];
	if (trace && trace.length) {
		msgStack.push('TRACE:');
		trace.forEach(function(t) {
			msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
		});
	}
	// uncomment to log into the console 
	console.error(msgStack.join('\n'));
};
page.open(url,function(status){
	var analyzeObj = page.evaluate(function(){
		//页面中dom提取的信息=========================================================
		var pageTitle = document.querySelector(".sku-name").textContent.trim();	//页面中标题
		var price = document.querySelector("span.p-price > span.price").textContent;	//价格
		var default_img = document.querySelector("#spec-img").getAttribute("data-origin");	//页面中默认图片地址
		
		var obj = {pageTitle:pageTitle,price:price,defaultImg:default_img}
		return obj;
	});
	var retObj = {};
	retObj.platform = 'jd';
	retObj.analyzeObj = analyzeObj;
	console.log(JSON.stringify(retObj));
	phantom.exit();
});